KAISER_SOZE
|
Adept
|
|
|
Reged: 05/09/03
|
Posts: 307
|
Loc: Silgrad Tower
|
|
|
What kind of AI specifications are needed to archieve the following.
When you come close to a creature it runs away for a certain amount of units into a random direction.
When you use getdistance etc you should be able to trigger it.. but since I do not know any AI that does that.. it becomes diffult.. anyone?
-D-
-------------------- =Deus=
Join us at Silgrad Tower
Post Extras:
|
cyran0
|
Initiate
|
|
|
Reged: 06/04/04
|
Posts: 58
|
|
|
|
It is problematic, but not impossible to make the creature run a certain distance. Since time and distance are equivalent, could you live with using the former to determine ‘how far’ the creature runs? Here’s a crude script (others here may help us troubleshoot it).
You may select a different distance than 1000 to trigger the script. Random 360 selects a direction, but I can’t remember if SetAngle requires measurements in degrees or minutes of arc. An extra line multiplying newFacing by 60 will solve that. It is truly a random direction, so it could be in the general direction of the player. It is possible to change that is you wish. The duration 3 seconds for running can be adjusted when you see how it performs. There is not collision detection provided, so if the creature reaches an obstacle before time expires, it will run in place or slide off the obstruction. A shorter duration will make that less likely and the make the movement appear more erratic (which could be desirable). It just occurred to me that a random duration could be used as well:
Code:
float duration set duration to random 20 set duration to ( duration + 10 ) set duration to ( duration / 10 ) if ( timer <= duration ) etc.
This would have the creature run between 1 and 3 seconds each episode to the nearest tenth of a second. Here’s the original script:
Code:
Begin ScaredyCat short state float newFacing float timer if ( player -> GetDistance “Creature_ID” < 1000 ) set state to 1 set newFacing to Random, 360 SetAngle, z, newFacing endif if ( state == 1 ) “Creature_ID” -> ForceRun set state to 2 endif if ( state == 2 ) set timer to ( timer + GetSecondsPassed ) if ( timer >= 3 ) set timer to 0 set state to 0 “Creature_ID” -> ClearForceRun return endif endif End ScaredyCat
Post Extras:
|
CyberFox
|
Novice
|
|
|
Reged: 08/22/04
|
Posts: 37
|
|
|
|
When you are in the CS, open the script editor, help, functions: AiFollow
Post Extras:
|
Erstam
|
Initiate
|
|
|
Reged: 06/22/04
|
Posts: 57
|
|
|
|
The solution is quite simple (supposed you have a script running on the creature): when the player comes close, set the flee parameter to 1000 and put it in combat mode. The following code should work:
Code:
short fleeState if ( fleeState == 0 ) if ( GetDistance player < 500 ) SetFlee 1000 StartCombat player set fleeState to 1 endif endif if ( fleeState == 1 ) if ( GetDistance player > 1500 ) StopCombat SetFlee 30 AIWander 0 0 0 set fleeState to 0 endif endif
Post Extras:
|
KAISER_SOZE
|
Adept
|
|
|
Reged: 05/09/03
|
Posts: 307
|
Loc: Silgrad Tower
|
|
|
Erstam,
Its kind of funny, but before asking this question I had a script almost 100% the same like you did.. but it had 2 problems.
1. In attackmode guards will attack the creature ( a chicken in my case) 2. The animal is simply too damned slow
and a 3rd actually.. sometimes flee causes the actor to literly flee up against the player
Can these 3 problems points be regulated on a way I cant think of?
-D-
-------------------- =Deus=
Join us at Silgrad Tower
Post Extras:
|
Erstam
|
Initiate
|
|
|
Reged: 06/22/04
|
Posts: 57
|
|
|
|
OK, when guards are near, the combat/flee method rules out...
Creature speed is determined by two factors: the "native" movement speed (one Walk/RunForward anim cycle in the NIF) and the CS Speed setting, which modifies the time to complete one of those cycles. For some creature models, you may have to set the creature's speed to an insanely high value - up to 500, or more.
As for actors fleeing up against the player... yeah, Morrowind's wonky movement AI...
As AITravel doesn't take variables, I'm quite at a loss to find an easy solution. There may be a way, but it's just an idea, haven't tested it yet: Create an invisible unique creature, place it at a spot, say, five times the chicken's distance to the player (formula: targetX = playerX + (chickenX - playerX) * 5, same for Y), and make the chicken AIFollow that creature, ForceRun and SetSpeed 500.
Perhaps an activator will serve this purpose as well, then the chicken needs to AIActivate it. Don't know if it works for creatures, but it never works across cell boundaries, even if it's just a few steps away.
Well, a lot of effort for a simple problem...
Post Extras:
|
Simpleton
|
Acolyte
|
|
|
Reged: 07/02/04
|
Posts: 138
|
Loc: Earlham College, Richmond, IN
|
|
|
That's what I was going to suggest, invisible creature and using aifollow. If the basic idea works you can do what you wanted with the random direction thing. Get a random number of 360 then sin angle for the y and then sqrt(1-y^2) for x. Then just multiply x and y by how far you want to go and add them to your current postion. oh, all this would be then invis creature, ya... gl.
btw, there is a slight problem with hills, since the creatuer will attempt to either move into the hill, or way off the ground... you also might be a problem if you're next to a cliff.
-------------------- Do you have a burning desire to give me money?
Click Here to Donate
Post Extras:
|
Erstam
|
Initiate
|
|
|
Reged: 06/22/04
|
Posts: 57
|
|
|
|
The good thing with creatures is, when you place one below terrain height, the engine will bump it instantly to the surface. Somone has made use of this behavior to measure terrain height, if I recall correctly. However, there will be problems with statics and other objects. It's quite easy to place a creature inside a house (or a large rock), and the AIFollow algorithm won't find it in this case.
Post Extras:
|